﻿@{
    ViewBag.Title = "备料";
    Layout = "~/Views/Shared/FrameWorkList.cshtml";
}

<div class="functionHeader" style="width:97%;text-align:left;margin:0px;margin-top:0px;margin-bottom:0px; border-bottom:2px solid #CCC;">
        <div class="lsider">
            <div class="updowninput btn-group" style="margin-top:10px;">
                <input id="radio11" class="category" name="category" value="登记" checked="checked" type="radio"><label for="radio11" class="suffix">登记</label><br>
                <input id="radio12" class="category" name="category" value="档案" type="radio"><label for="radio12" class="suffix">档案</label>
            </div>
            <div class="updowninput" style="width:160px;height:20px;margin-left:10px;">
                <p>领料单位</p>
                <select id="txtFHappenCompanyNO" name="FHappenCompanyNO" class="form-control">
                    <option value="">==请选择==</option>
                </select>
            </div>
            <div class="updowninput" style="width:120px;height:20px;margin-left:10px;">
                <p>零部件号</p>
                <input type="text" id="txt_FDocuTypeNO" class="form-control required" />
                &nbsp;
            </div>
            <div class="updowninput" style="width:120px;height:20px;margin-left:10px;">
                <p>供货单位</p>
                <select id="txtqueryFProCompanyNO" class="form-control">
                    <option >==请选择==</option>
                </select>
            </div>
            <div class="updowninput" style="width:120px;height:20px;margin-left:10px;">
                <p>出库日期</p>
                <input type="text" class="form-control required input-wdatepicker" onfocus="WdatePicker()" />
                &nbsp;
            </div>
            <div class="updowninput" style="width:120px;height:20px;margin-left:10px;">
                <p>凭证编号</p>
                <input type="text" class="form-control required" />
                &nbsp;
            </div>
            <div class="updowninput" style="width:100px;margin-left:10px;">
                <p>台账日期</p>
                <input id="txtqueryFAccountDate" type="text" class="form-control required input-wdatepicker" onfocus="WdatePicker({ dateFmt: 'yyyyMM', isShowToday: false, isShowClear: false });" />
                &nbsp;
            </div>
            <div class="btn-group" style="margin-top:12px;margin-left:10px;">
                &nbsp;
                <a id="btn_search" class="btn btn-primary center-block" onclick=""><span class="glyphicon glyphicon-search"></span>  &nbsp; 查询</a>
            </div>
        </div>

        <div class="rsider">
            <div class="btn-group btn-operration" style="float:right;margin-top:12px;">
                <a class="btn btn-primary center-block" onclick="$.reload()">  <span class="glyphicon glyphicon-refresh"> </span>&nbsp刷新</a>
                <a class="btn btn-primary center-block active" onclick="btn_Delete()"><span class="glyphicon glyphicon-trash">   </span>&nbsp删除</a>
                <a class="btn btn-primary center-block active" onclick="btn_operration_Edit()"><span class="glyphicon glyphicon-trash">   </span>&nbsp修改</a>
                <a class="btn btn-primary center-block active" onclick="btn_Add()">   <span class="glyphicon glyphicon-plus">    </span>&nbsp出库</a>               
                <a class="btn btn-primary center-block " onclick="btn_Print()"> <span class="glyphicon glyphicon-print">   </span>&nbsp打印</a>
                <a class="btn btn-primary center-block" onclick="btn_Excel()"> <span class="glyphicon glyphicon-download"></span>&nbsp导出</a>
            </div>
        </div>
    <div class="btn-group btn-edit-entity" style="float:left;margin-top:12px;display:none;">
        <a class="btn btn-primary center-block" onclick="btn_Edit();">   <span class="glyphicon ">    </span>修改</a>
        <a class="btn btn-primary center-block" onclick="btn_Cancel();"><span class="glyphicon ">   </span>关闭</a>
    </div>
    </div>

<table id="eidt_entity" class="form" style="width:600px; text-align: left; margin:0 auto 5px 20px;display:none;">
    <tr>
        <th class="formTitle">零件编号</th>
        <td class="formValue" style="width:140px;">
            <input id="txtFProductionNO" name="FProductionNO" class="form-control" readonly="readonly" type="text">
        </td>
        <th class="formTitle">仓库</th>
        <td class="formValue" style="width:140px;">
            <select id="txtFStoreNO" name="FStoreNO" class="form-control required">
                <option>==请选择==</option>
            </select>
        </td>
        <th class="formTitle" style="width:80px;text-align:center;">库存数量</th>
        <th class="formTitle" style="width:80px;text-align:center;">实际数量</th>
        <th class="formTitle" style="width:80px;text-align:center;">容器数量</th>
        <th class="formTitle" style="width:80px;text-align:center;">托盘数量</th>
    </tr>
    <tr>
        <th class="formTitle">零件名称</th>
        <td class="formValue">
            <input id="txtFProductionName" name="FProductionName" class="form-control" readonly="readonly" type="text">
        </td>
        <th class="formTitle">库位编码</th>
        <td class="formValue">
            <select id="txtFStoreSetNO" name="FStoreSetNO" class="form-control required">
                <option>==请选择==</option>
            </select>
        </td>
        <td class="formValue">
            <input id="txtStoreSetNOInventoryQty" name="StoreSetNOInventoryQty" class="form-control decimal suffix"  readonly="readonly" style="width:50px;margin-left:2px;" type="text">
        </td>
        <td class="formValue">
            <input id="txtFQuantity" name="FQuantity" class="form-control decimal suffix" style="width:50px;margin-left:2px;" type="text"><label class="suffix">件</label>
        </td>
        <td class="formValue">
            <input id="txtFContainerName" name="FContainerName" class="form-control suffix" style="width:50px;margin-left:2px;"  type="text"><label class="suffix">箱</label>
        </td>
        <td class="formValue">
            <input id="txtFContainerQuantity" name="FContainerQuantity" class="form-control decimal suffix" style="width:50px;margin-left:2px;" type="text"><label class="suffix">托</label>
        </td>
    </tr>
</table>

<div id="stockpreparationReg">
    <table id="gridstockpreparationRegList"></table>
    <div id="gridstockpreparationRegPager"></div>
</div>

<div id="stockpreparationArchives">
    <table id="gridstockpreparationArchivesList"></table>
    <div id="gridstockpreparationArchivesPager"></div>
</div>



<script>
    var rowData = {};
    var index = -1;
    var proCompanyNO = "";
    var productionTypeNO = "";
    var FAccountDate=@ViewBag.FAccountDate;
    $(function () {
        initControl();
        gridstockpreparationRegList();
    });
    function initControl() {
        $('.category').on("click", function () {
            var flag = $("input[type='radio'].category:checked").val();
            if (flag == '登记') {
                gridstockpreparationRegList();
            } else {
                gridstockpreparationArchivesList();
            }
        });
        //领料单位
        $("#txtFHappenCompanyNO").bindSelect({
            url: "/BaseData/ZSJ_B1_GH_SI/GetGridJson?isCustomer=1",
            id: "UnitNO",
            text: "UnitNOShortName",
            search: true
        });
        //供货单位
        $("#txtqueryFProCompanyNO").bindSelect({
            url: "/BaseData/ZSJ_B1_GH_SI/GetProCompany?isProduct=1",
            id: "UnitNO",
            text: "UnitNOShortName",
            search: true
        });
        //台帐日期赋初值
        $("#txtqueryFAccountDate").val(FAccountDate);
    }

    //登记
    function showReg() {
        $("#stockpreparationReg").show();
        $("#stockpreparationArchives").hide();
        $(".rsider .active").show();
    }
    //档案
    function showArc() {
        $("#stockpreparationReg").hide();
        $("#stockpreparationArchives").show();
        $(".rsider .active").hide();
    }

    function gridstockpreparationRegList() {
        showReg();
        var $gridList = $("#gridstockpreparationRegList");
        var url="/VBaseData/V_CPK_32_BL_StoArcPreMaterial_Mid/GetStockpreparationRegList";
        if(FAccountDate!=$("#txtqueryFAccountDate").val()){
            url="/VBaseData/V_CPK_33_BL_StoArcPreMaterial_Arc/GetStockpreparationRegList";
        }
        $gridList.dataGridForJson({
            url: url,
            height: $(window).height() - 170,
            colModel: [
            { label: '备料主键', name: 'FPreMaterialID', width: 80, align: 'left', hidden: true },
            { label: '登记ID', name: 'FRegisterID', width: 80, align: 'left', hidden: true },
            { label: '<input id="selectAll" type="checkbox" style="text-align:center;">', width: 60, align: 'center', sortable: false, formatter: $.checkbox, unformat: $.empty },
            { label: '备料单号', name: 'FPreMaterialNO', width: 140, align: 'left' },
            { label: '领料单位', name: 'FHappenComNO', width: 80, align: 'left' },
            { label: '领料单位名称', name: 'FHappenComShortName', width: 140, align: 'left' },
            { label: '出库日期', name: 'FCurDate', width: 80, align: 'center' },
            { label: '零件编号', name: 'FProductionNO', width: 100, align: 'left' },
            { label: '零件名称', name: 'FProductionName', width: 140, align: 'left' },
            { label: '批次号', name: 'FStoreBatch', width: 80, align: 'left' },
            { label: '开票数量', name: 'FQuantity_KP', width: 80, align: 'right' },
            { label: '实际数量', name: 'FQuantity', width: 80, align: 'right' },
            { label: '仓库编号', name: 'FStoreNO', width: 80, align: 'left' },
            { label: '库位编号', name: 'FStoreSetNO', width: 80, align: 'left' },
            { label: '容器编号', name: 'FContainerNO', width: 80, align: 'left' },
            { label: '容器名称', name: 'FContainerName', width: 80, align: 'left' },
            { label: '容器数量', name: 'FContainerQuantity', width: 80, align: 'right' },
            { label: '实际装箱', name: 'FFactContent', width: 80, align: 'right' },
            { label: '标准装箱', name: 'FContent', width: 80, align: 'right' },
            { label: '托盘编号', name: 'FPalletNO', width: 80, align: 'left' },
            { label: '托盘数量', name: 'FPalletQuantity', width: 80, align: 'right' },
            { label: '实际容量', name: 'FPalletFactContent', width: 80, align: 'right' },
            { label: '标准容量', name: 'FPalletContent', width: 80, align: 'right' },
            { label: '凭证编号', name: 'FVoucherNo', width: 80, align: 'left' },
            { label: '备注', name: 'Fdescription', width: 80, align: 'left' },
            { label: '供货单位', name: 'FSupplierNO', width: 80, align: 'left' },
            { label: '供货单位名称', name: 'FSupplierName', width: 80, align: 'left' },
            { label: '零件分类', name: 'FProductionTypeNO', width: 80, align: 'left',hidden:true},
            { label: '零件分类', name: 'FProductionTypeName', width: 80, align: 'left' },
            { label: '编制人员', name: 'FCreateBy', width: 80, align: 'left' },
            { label: '编制日期', name: 'FCreateDate', width: 80, align: 'left' },
            { label: '编制时间', name: 'FCreateTime', width: 80, align: 'left' },
            { label: '保管员', name: 'FStoreBy', width: 80, align: 'left' },
            { label: '审核日期', name: 'FUpdateDate', width: 80, align: 'left' },
            { label: '审核时间', name: 'FUpdateDate', width: 80, align: 'left' },
            { label: 'FRegisterID_ZL', name: 'FRegisterID_ZL', width: 80, align: 'left',hidden:true }
            ],
            pager: "#gridstockpreparationRegPager",
            sortname: 'FPreMaterialNO asc',
            viewrecords: true,
            onSelectRow: function (rowId) {
                rowData = $gridList.jqGrid('getRowData', rowId);
                index = rowId;
                $.each(rowData, function (key, value) {
                    $("#txt" + key).val(value);
                });
                proCompanyNO = rowData["FSupplierNO"];
                productionTypeNO = rowData["FProductionTypeNO"];
                $("#txtFStoreSetNO").val(rowData["FRegisterID_ZL"]).trigger("change");
            }
        });
    }

    function gridstockpreparationArchivesList() {
        showArc();
        var $gridList = $("#gridstockpreparationArchivesList");
        $gridList.dataGridForJson({
            url: "/VBaseData/V_CPK_31_BL_StoArcPreMaterial/GetStockpreparationRegList",
            height: $(window).height() - 170,
            colModel: [
            { label: '备料主键', name: 'FPreMaterialID', width: 80, align: 'left', hidden: true },
            { label: '登记ID', name: 'FRegisterID', width: 80, align: 'left', hidden: true },
            { label: '<input id="selectAll" type="checkbox" style="text-align:center;">', width: 60, align: 'center', sortable: false, formatter: $.checkbox, unformat: $.empty },
            { label: '出库单号', name: 'FDocuNO', width: 80, align: 'left' },
            { label: '备料单号', name: 'FPreMaterialNO', width: 80, align: 'left' },
            { label: '领料单位', name: 'FHappenComNO', width: 80, align: 'left' },
            { label: '领料单位名称', name: 'FHappenComShortName', width: 80, align: 'left' },
            { label: '出库日期', name: 'FCurDate', width: 80, align: 'left' },
            { label: '零件编号', name: 'FProductionNO', width: 80, align: 'left' },
            { label: '零件名称', name: 'FProductionName', width: 80, align: 'left' },
            { label: '批次号', name: 'FStoreBatch', width: 80, align: 'left' },
            { label: '开票数量', name: 'FQuantity_KP', width: 80, align: 'left' },
            { label: '实际数量', name: 'FQuantity', width: 80, align: 'left' },
            { label: '仓库编号', name: 'FStoreNO', width: 80, align: 'left' },
            { label: '库位编号', name: 'FStoreSetNO', width: 80, align: 'left' },
            { label: '容器编号', name: 'FContainerNO', width: 80, align: 'left' },
            { label: '容器名称', name: 'FContainerName', width: 80, align: 'left' },
            { label: '容器数量', name: 'FContainerQuantity', width: 80, align: 'left' },
            { label: '实际装箱', name: 'FFactContent', width: 80, align: 'left' },
            { label: '标准装箱', name: 'FContent', width: 80, align: 'left' },
            { label: '托盘编号', name: 'FPalletNO', width: 80, align: 'left' },
            { label: '托盘数量', name: 'FPalletQuantity', width: 80, align: 'left' },
            { label: '实际容量', name: 'FPalletFactContent', width: 80, align: 'left' },
            { label: '标准容量', name: 'FPalletContent', width: 80, align: 'left' },
            { label: '凭证编号', name: 'FVoucherNo', width: 80, align: 'left' },
            { label: '备注', name: 'Fdescription', width: 80, align: 'left' },
            { label: '供货单位', name: 'FSupplierNO', width: 80, align: 'left' },
            { label: '供货单位名称', name: 'FSupplierName', width: 80, align: 'left' },
            { label: '零件分类', name: 'FProductionTypeNO', width: 80, align: 'left' },
            { label: '编制人员', name: 'FCreateBy', width: 80, align: 'left' },
            { label: '编制日期', name: 'FCreateDate', width: 80, align: 'left' },
            { label: '编制时间', name: 'FCreateTime', width: 80, align: 'left' },
            { label: '保管员', name: 'FStoreBy', width: 80, align: 'left' },
            { label: '审核日期', name: 'FUpdateDate', width: 80, align: 'left' },
            { label: '审核时间', name: 'FUpdateDate', width: 80, align: 'left' },
            { label: 'FRegisterID_ZL', name: 'FRegisterID_ZL', width: 80, align: 'left', hidden: true }
            ],
            pager: "#gridstockpreparationArchivesPager",
            sortname: 'FPreMaterialNO asc',
            viewrecords: true,
            onSelectRow: function (rowId) {
                rowData = $gridList.jqGrid('getRowData', rowId);
                index = rowId;
                $.each(rowData, function (key, value) {
                    $("#txt" + key).val(value);
                });
            }
        });
    }

    function btn_operration_Edit() {
        $.showOrHide($(".btn-operration"));
        $.showOrHide($("#eidt_entity"));
        $.showOrHide($(".btn-edit-entity"));

        //仓库编号
        $("#txtFStoreNO").clearSelect();
        $("#txtFStoreNO").bindSelect({
            url: "/BaseData/CPK_ZD_11_DatStoreHouse/GetStoreHouses",
            id: "FStoreNO",
            text: "FStoreNO",
            search: true
        });
        //库位编号
        storeSetNO();
        //仓库库位联动
        $("#txtFStoreNO").on("change", function () {
            //库位编号
            storeSetNO();
        });
        //库位数据变化
        $("#txtFStoreSetNO").on("change", function () {
            var jsonData = JSON.parse($(this).find("option:selected").attr("obj"));
            $("#txtStoreSetNOInventoryQty").val(jsonData["StoreSetNOInventoryQty"]);
        });

    }
    function storeSetNO() {
        //库位编号
        $("#txtFStoreSetNO").clearSelect();
        $("#txtFStoreSetNO").bindSelect({
            url: "/BaseData/CPK_61_PC_StoCPKAIAOAcco/GetStoCPKAIAOAccoForOutStock",
            id: "FInOutID",
            text: "StoreSetNOInventoryQty",
            param: { productionNO: $("#txtFProductionNO").val(), proCompanyNO: proCompanyNO, productionTypeNO: productionTypeNO, storeNO: $("#txtFStoreNO").val() },
            search: true
        });
    }

    function btn_Cancel(){

        $.showOrHide($(".btn-operration"));
        $.showOrHide($("#eidt_entity"));
        $.showOrHide($(".btn-edit-entity"));
        $.each(rowData, function (key, value) {
            rowData[key] = "";
        });
    }

    function btn_Ok() {
        $.each(rowData, function (key, value) {
            rowData[key] = $("#txt" + key).val();
        });
        $("#gridListNote").jqGrid('setRowData', index, rowData);
    }

    function btn_Add() {
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/WareHouse/EnterWareHouse/WareHouseMaterialInput"
        });
    }

    function btn_Edit() {
        if ($("#txtStoreSetNOInventoryQty").val() < $("#txtFQuantity").val()) {
            $.modalAlert("实际数量不能大于库存数量", "error");
            return false;
        }
        //$.each(rowData, function (key, value) {
        //    if ($("#txt" + key).val()) {
        //        rowData[key] = $("#txt" + key).val();
        //    }
        //});
        //$.submitForm({
        //    url: "/WareHouse/EnterWareHouse/EditInStoreDetail",
        //    param: rowData,
        //    success: function () {
        //        $("#gridList1").resetSelection();
        //        $("#gridList1").trigger("reloadGrid");
        //    }
        //});
    }
    //打印备料单
    function btn_Print() {
        var dataArray = [];
        $("#gridList1 input:checkbox:checked").each(function () {
            var rowid = $(this).attr("value");
            dataArray.push($("#gridList1").jqGrid('getRowData', rowid).FPreMaterialNO);
        });
        $.detailOpen({
            id: "PrintPrepare",
            title: "",
            url: "/WareHouse/EnterWareHouse/PrintPrepare?data=" + dataArray.join(',')
        });
    }
</script> 